package com.slt.developkitweb.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * 工具类，用于读取和处理 User 类文件。
 */
public class UserFileUtils {

    /**
     * 读取原始文件并生成新的文件格式。
     *
     * @param originalFilePath 原始文件路径
     * @param newFilePath 新文件路径
     */
    public static void processUserFile(String originalFilePath, String newFilePath) {
        try (BufferedReader reader = new BufferedReader(new FileReader(originalFilePath));
             FileWriter writer = new FileWriter(newFilePath)) {
            String line;
            StringBuilder contentBuilder = new StringBuilder();

            while ((line = reader.readLine()) != null) {
                contentBuilder.append(line).append("\n");
            }

            String originalContent = contentBuilder.toString();
            String newContent = transformContent(originalContent);

            writer.write(newContent);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 转换文件内容。
     *
     * @param originalContent 原始文件内容
     * @return 转换后的新文件内容
     */
    private static String transformContent(String originalContent) {
        // 替换注释和添加 Lombok 注解
        String newContent = originalContent
                .replace("// 用户的姓名。", "@ApiModelProperty(\"用户的姓名。\")")
                .replace("// 用户的年龄。", "@ApiModelProperty(\"用户的年龄。\")")
                .replace("// 用户的身高（单位：厘米）。", "@ApiModelProperty(\"用户的身高（单位：厘米）。\")")
                .replace("// 用户的体重（单位：千克）。", "@ApiModelProperty(\"用户的体重（单位：千克）。\")")
                .replace("private String name;", "private String name;")
                .replace("private int age;", "private int age;")
                .replace("private double height;", "private double height;")
                .replace("private double weight;", "private double weight;")
                .replace("public class User {", "@Data\npublic class User {");

        return newContent;
    }

    public static void main(String[] args) {
        String originalFilePath = "path/to/original/User.java";
        String newFilePath = "path/to/new/User.java";

        processUserFile(originalFilePath, newFilePath);
    }
}
